Micron Document
`:top
In the `F33f`_`[Java computer programming language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_(programming_language)]`_`f, an `!annotation`! is a form of syntactic `F33f`_`[metadata`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Metadata]`_`f that can be added to Java `F33f`_`[source code`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Source_code]`_`f, like an `F33f`_`[attribute`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Attribute_(computing)]`_`f.`:cite-ref-1[`F5bf`_`[1`#cite-note-1]`_`f] `F33f`_`[Classes`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Class_(computer_programming)]`_`f, `F33f`_`[methods`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Method_(computer_programming)]`_`f, `F33f`_`[variables`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Variable_(computer_science)]`_`f, `F33f`_`[parameters`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Parameter_(computer_programming)]`_`f and `F33f`_`[Java packages`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_package]`_`f may be annotated. Like `F33f`_`[Javadoc`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Javadoc]`_`f tags, Java annotations can be read from source files. Unlike `F33f`_`[Javadoc`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Javadoc]`_`f tags, Java annotations can also be embedded in and read from `F33f`_`[Java class files`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_class_file]`_`f generated by the `F33f`_`[Java compiler`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_compiler]`_`f. This allows annotations to be retained by the `F33f`_`[Java virtual machine`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_virtual_machine]`_`f at `F33f`_`[run-time`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Run_time_(program_lifecycle_phase)]`_`f and read via `F33f`_`[reflection`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Reflection_(computer_science)]`_`f.`:cite-ref-2[`F5bf`_`[2`#cite-note-2]`_`f] It is possible to create meta-annotations out of the existing ones in Java.`:cite-ref-3[`F5bf`_`[3`#cite-note-3]`_`f]

>>Contents

• `F0af`_`[History`#history]`_`f
• `F0af`_`[Built-in annotations`#built-in-annotations]`_`f
• `F0af`_`[Example`#example]`_`f
• `F0af`_`[Built-in annotations`#built-in-annotations]`_`f
• `F0af`_`[Custom annotations`#custom-annotations]`_`f
• `F0af`_`[Processing`#processing]`_`f
• `F0af`_`[See also`#see-also]`_`f
• `F0af`_`[References`#references]`_`f
• `F0af`_`[External links`#external-links]`_`f

-─

>>History

The `F33f`_`[Java platform`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_(software_platform)]`_`f has various `*ad-hoc`* annotation mechanisms—for example, the `*`B100`F9d9transient`f`b`* modifier, or the `*`B100`F9d9@Deprecated`f`b`* javadoc tag. The `F33f`_`[Java Specification Request`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Specification_Request]`_`f JSR-175 introduced the general-purpose annotation (also known as `*metadata`*) facility to the `F33f`_`[Java Community Process`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Community_Process]`_`f in 2002; it gained approval in September 2004.`:cite-ref-4[`F5bf`_`[4`#cite-note-4]`_`f]

Annotations became available in the language itself beginning with version 1.5 of the `F33f`_`[Java Development Kit`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Development_Kit]`_`f (JDK). The `F33f`_`[apt tool`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Annotation_processing_tool]`_`f provided a provisional interface for compile-time annotation processing in JDK version 1.5; JSR-269 formalized this, and it became integrated into the `F33f`_`[javac`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Javac]`_`f compiler in version 1.6.

In `F33f`_`[C++26`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=C++26]`_`f, `F33f`_`[C++`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=C++]`_`f added annotations for reflection that are similar to Java annotations.

>>Built-in annotations

Java defines a set of annotations that are built into the language. Of the seven standard annotations, three are part of `F33f`_`[java.lang`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java.lang]`_`f, and the remaining four are imported from java.lang.annotation.`:cite-ref-5[`F5bf`_`[5`#cite-note-5]`_`f]`:cite-ref-6[`F5bf`_`[6`#cite-note-6]`_`f]

`!Annotations applied to Java code:`!

• `B100`F9d9@Override`f`b — Checks that the method is an `F33f`_`[override`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Method_overriding]`_`f. Causes a `F33f`_`[compilation error`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Compilation_error]`_`f if the method is not found in one of the `F33f`_`[parent classes`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Parent_class]`_`f or implemented `F33f`_`[interfaces`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Interface_(Java)]`_`f.
• `B100`F9d9@Deprecated`f`b — Marks the method as obsolete. Causes a compile warning if the method is used.
• `B100`F9d9@SuppressWarnings`f`b — Instructs the compiler to suppress the `F33f`_`[compile time`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Compile_time]`_`f warnings specified in the annotation parameters.

`!Annotations applied to other annotations (also known as "Meta Annotations"):`!

• `B100`F9d9@Retention`f`b — Specifies how the marked annotation is stored, whether in code only, compiled into the class, or available at runtime through reflection.
• `B100`F9d9@Documented`f`b — Marks another annotation for inclusion in the documentation.
• `B100`F9d9@Target`f`b — Marks another annotation to restrict what kind of Java elements the annotation may be applied to.
• `B100`F9d9@Inherited`f`b — Marks another annotation to be inherited to subclasses of annotated class (by default annotations are not inherited by subclasses).

Since Java 7, three additional annotations have been added to the language.

• `B100`F9d9@SafeVarargs`f`b — Suppress warnings for all callers of a method or constructor with a `F33f`_`[generics`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Generics_in_Java]`_`f `F33f`_`[varargs`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Variadic_function]`_`f parameter, since Java 7.
• `B100`F9d9@FunctionalInterface`f`b — Specifies that the `F33f`_`[type declaration`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Declaration_(computer_programming)]`_`f is intended to be a `F33f`_`[functional interface`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Anonymous_function]`_`f, since Java 8.
• `B100`F9d9@Repeatable`f`b — Specifies that the annotation can be applied more than once to the same declaration, since Java 8.

>>Example

>>>Built-in annotations

This example demonstrates the use of the `B100`F9d9@Override`f`b annotation. It instructs the compiler to check parent classes for matching methods. In this case, an error is generated because the `B100`F9d9gettype()`f`b method of class Cat doesn't in fact override `B100`F9d9getType()`f`b of class Animal like is desired, because of the `F33f`_`[mismatching case`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Case_sensitivity]`_`f. If the `B100`F9d9@Override`f`b annotation were absent, a new method of name `B100`F9d9gettype()`f`b would be created in class Cat.

`B100`F9d9public class Animal {`f`b
`B100`F9d9 public void speak() {`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 public String getType() {`f`b
`B100`F9d9 return "Generic animal";`f`b
`B100`F9d9 }`f`b
`B100`F9d9}`f`b
`B100`F9d9`f`b
`B100`F9d9public class Cat extends Animal {`f`b
`B100`F9d9 @Override`f`b
`B100`F9d9 public void speak() { // This is a good override.`f`b
`B100`F9d9 System.out.println("Meow.");`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 @Override`f`b
`B100`F9d9 public String gettype() { // Compile-time error due to typo: should be getType() not gettype().`f`b
`B100`F9d9 return "Cat";`f`b
`B100`F9d9 }`f`b
`B100`F9d9}`f`b

>>>Custom annotations

Annotation type declarations are similar to normal interface declarations. An at-sign (@) precedes the `F33f`_`[keyword`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Reserved_word]`_`f "interface".

`B100`F9d9 // @Twizzle is an annotation to method toggle().`f`b
`B100`F9d9 @Twizzle`f`b
`B100`F9d9 public void toggle() {`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 // Declares the annotation Twizzle.`f`b
`B100`F9d9 public @interface Twizzle {`f`b
`B100`F9d9 }`f`b

Annotations may include a set of key-value pairs, which are modeled as methods of the annotation type. Each method declaration defines an element of the annotation type. Method declarations must not have any parameters or a throws clause. Return types are restricted to `F33f`_`[primitives`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Primitive_data_type]`_`f, `F33f`_`[String`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=String_(computer_science)]`_`f, Class, `F33f`_`[enums`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Enumerated_type]`_`f, annotations, and `F33f`_`[arrays`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Array_data_type]`_`f of the preceding types. Methods can have `F33f`_`[default values`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Default_(computer_science)]`_`f.

`B100`F9d9 // Same as: @Edible(value = true)`f`b
`B100`F9d9 @Edible(true)`f`b
`B100`F9d9 Item item = new Carrot();`f`b
`B100`F9d9`f`b
`B100`F9d9 public @interface Edible {`f`b
`B100`F9d9 boolean value() default false;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 @Author(first = "Oompah", last = "Loompah")`f`b
`B100`F9d9 Book book = new Book();`f`b
`B100`F9d9`f`b
`B100`F9d9 public @interface Author {`f`b
`B100`F9d9 String first();`f`b
`B100`F9d9 String last();`f`b
`B100`F9d9 }`f`b

Annotations themselves may be annotated to indicate where and when they can be used:

`B100`F9d9 @Retention(RetentionPolicy.RUNTIME) // Make this annotation accessible at runtime via reflection.`f`b
`B100`F9d9 @Target({ElementType.METHOD}) // This annotation can only be applied to class methods.`f`b
`B100`F9d9 public @interface Tweezable {`f`b
`B100`F9d9 }`f`b

The compiler reserves a set of special annotations (including `B100`F9d9@Deprecated`f`b, `B100`F9d9@Override`f`b and `B100`F9d9@SuppressWarnings`f`b) for syntactic purposes.

Annotations are often used by `F33f`_`[frameworks`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Software_framework]`_`f as a way of conveniently applying behaviours to user-defined classes and methods that must otherwise be declared in an external source (such as an XML configuration file) or programmatically (with API calls). The following, for example, is an annotated `F33f`_`[JPA`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Persistence_API]`_`f data class:

`B100`F9d9@Entity // Declares this an entity bean`f`b
`B100`F9d9@Table(name = "people") // Maps the bean to SQL table "people"`f`b
`B100`F9d9public class Person implements Serializable {`f`b
`B100`F9d9 @Id // Map this to the primary key column.`f`b
`B100`F9d9 @GeneratedValue(strategy = GenerationType.AUTO) // Database will generate new primary keys, not us.`f`b
`B100`F9d9 private Integer id;`f`b
`B100`F9d9`f`b
`B100`F9d9 @Column(length = 32) // Truncate column values to 32 characters.`f`b
`B100`F9d9 private String name;`f`b
`B100`F9d9`f`b
`B100`F9d9 public Integer getId() {`f`b
`B100`F9d9 return id;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 public void setId(Integer id) {`f`b
`B100`F9d9 this.id = id;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 public String getName() {`f`b
`B100`F9d9 return name;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 public void setName(String name) {`f`b
`B100`F9d9 this.name = name;`f`b
`B100`F9d9 }`f`b
`B100`F9d9}`f`b

The annotations are not method calls and will not, by themselves, do anything. Rather, the class object is passed to the `F33f`_`[JPA`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Persistence_API]`_`f implementation at `F33f`_`[run-time`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Run_time_(program_lifecycle_phase)]`_`f, which then extracts the annotations to generate an `F33f`_`[object–relational mapping`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Object–relational_mapping]`_`f.

A complete example is given below:

`B100`F9d9package com.annotation;`f`b
`B100`F9d9`f`b
`B100`F9d9import java.lang.annotation.Documented;`f`b
`B100`F9d9import java.lang.annotation.ElementType;`f`b
`B100`F9d9import java.lang.annotation.Inherited;`f`b
`B100`F9d9import java.lang.annotation.Retention;`f`b
`B100`F9d9import java.lang.annotation.RetentionPolicy;`f`b
`B100`F9d9import java.lang.annotation.Target;`f`b
`B100`F9d9`f`b
`B100`F9d9@Documented`f`b
`B100`F9d9@Retention(RetentionPolicy.RUNTIME)`f`b
`B100`F9d9@Target({ElementType.TYPE,ElementType.METHOD,`f`b
`B100`F9d9 ElementType.CONSTRUCTOR,ElementType.ANNOTATION_TYPE,`f`b
`B100`F9d9 ElementType.PACKAGE,ElementType.FIELD,ElementType.LOCAL_VARIABLE})`f`b
`B100`F9d9@Inherited`f`b
`B100`F9d9`f`b
`B100`F9d9public @interface Unfinished {`f`b
`B100`F9d9 public enum Priority { LOW, MEDIUM, HIGH }`f`b
`B100`F9d9 String value();`f`b
`B100`F9d9 String[] changedBy() default "";`f`b
`B100`F9d9 String[] lastChangedBy() default "";`f`b
`B100`F9d9 Priority priority() default Priority.MEDIUM;`f`b
`B100`F9d9 String createdBy() default "James Gosling";`f`b
`B100`F9d9 String lastChanged() default "2011-07-08";`f`b
`B100`F9d9}`f`b

`B100`F9d9package com.annotation;`f`b
`B100`F9d9`f`b
`B100`F9d9public @interface UnderConstruction {`f`b
`B100`F9d9 String owner() default "Patrick Naughton";`f`b
`B100`F9d9 String value() default "Object is Under Construction.";`f`b
`B100`F9d9 String createdBy() default "Mike Sheridan";`f`b
`B100`F9d9 String lastChanged() default "2011-07-08";`f`b
`B100`F9d9}`f`b

`B100`F9d9package com.validators;`f`b
`B100`F9d9`f`b
`B100`F9d9import javax.faces.application.FacesMessage;`f`b
`B100`F9d9import javax.faces.component.UIComponent;`f`b
`B100`F9d9import javax.faces.context.FacesContext;`f`b
`B100`F9d9import javax.faces.validator.Validator;`f`b
`B100`F9d9import javax.faces.validator.ValidatorException;`f`b
`B100`F9d9`f`b
`B100`F9d9import com.annotation.UnderConstruction;`f`b
`B100`F9d9import com.annotation.Unfinished;`f`b
`B100`F9d9import com.annotation.Unfinished.Priority;`f`b
`B100`F9d9import com.util.Util;`f`b
`B100`F9d9`f`b
`B100`F9d9@UnderConstruction(owner="Jon Doe")`f`b
`B100`F9d9public class DateValidator implements Validator {`f`b
`B100`F9d9`f`b
`B100`F9d9 public void validate(FacesContext context, UIComponent component, Object value)`f`b
`B100`F9d9 throws ValidatorException {`f`b
`B100`F9d9 String date = (String) value;`f`b
`B100`F9d9 String errorLabel = "Please enter a valid date.";`f`b
`B100`F9d9 if (!component.getAttributes().isEmpty()) {`f`b
`B100`F9d9 errorLabel = (String) component.getAttributes().get("errordisplayval");`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 if (!Util.validateAGivenDate(date)) {`f`b
`B100`F9d9 @Unfinished(changedBy = "Steve",`f`b
`B100`F9d9 value = "whether to add message to context or not, confirm",`f`b
`B100`F9d9 priority = Priority.HIGH`f`b
`B100`F9d9 )`f`b
`B100`F9d9 FacesMessage message = new FacesMessage();`f`b
`B100`F9d9 message.setSeverity(FacesMessage.SEVERITY_ERROR);`f`b
`B100`F9d9 message.setSummary(errorLabel);`f`b
`B100`F9d9 message.setDetail(errorLabel);`f`b
`B100`F9d9 throw new ValidatorException(message);`f`b
`B100`F9d9 }`f`b
`B100`F9d9 }`f`b
`B100`F9d9}`f`b

>>Processing

When Java source code is compiled, annotations can be processed by compiler plug-ins called annotation processors. Processors can produce informational messages or create additional Java source files or resources, which in turn may be compiled and processed. However, annotation processors cannot modify the annotated code itself. (Code modifications may be implemented using methods beyond the Java Language Specification.) The Java compiler conditionally stores annotation metadata in the class files, if the annotation has a `B100`F9d9RetentionPolicy`f`b of `B100`F9d9CLASS`f`b or `B100`F9d9RUNTIME`f`b. Later, the `F33f`_`[JVM`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_virtual_machine]`_`f or other programs can look for the metadata to determine how to interact with the program elements or change their behavior.

In addition to processing an annotation using an annotation processor, a Java programmer can write their own code that uses reflection to process the annotation. `F33f`_`[Java SE`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Platform,_Standard_Edition]`_`f 5 supports a new interface that is defined in the `B100`F9d9java.lang.reflect`f`b package. This package contains the interface called `B100`F9d9AnnotatedElement`f`b that is implemented by the Java reflection classes including `B100`F9d9Class`f`b, `B100`F9d9Constructor`f`b, `B100`F9d9Field`f`b, `B100`F9d9Method`f`b, and `B100`F9d9Package`f`b. The implementations of this interface are used to represent an annotated element of the program currently running in the Java Virtual Machine. This interface allows annotations to be read reflectively.

The `B100`F9d9AnnotatedElement`f`b interface provides access to annotations having `B100`F9d9RUNTIME`f`b retention. This access is provided by the `B100`F9d9getAnnotation`f`b, `B100`F9d9getAnnotations`f`b, and `B100`F9d9isAnnotationPresent`f`b methods. Because annotation types are compiled and stored in byte code files just like classes, the annotations returned by these methods can be queried just like any regular Java object. A complete example of processing an annotation is provided below:

`B100`F9d9import java.lang.annotation.Retention;`f`b
`B100`F9d9import java.lang.annotation.RetentionPolicy;`f`b
`B100`F9d9`f`b
`B100`F9d9// This is the annotation to be processed`f`b
`B100`F9d9// Default for Target is all Java Elements`f`b
`B100`F9d9// Change retention policy to RUNTIME (default is CLASS)`f`b
`B100`F9d9@Retention(RetentionPolicy.RUNTIME)`f`b
`B100`F9d9public @interface TypeHeader {`f`b
`B100`F9d9 // Default value specified for developer attribute`f`b
`B100`F9d9 String developer() default "Unknown";`f`b
`B100`F9d9 String lastModified();`f`b
`B100`F9d9 String [] teamMembers();`f`b
`B100`F9d9 int meaningOfLife();`f`b
`B100`F9d9}`f`b

`B100`F9d9// This is the annotation being applied to a class`f`b
`B100`F9d9@TypeHeader(developer = "Bob Bee",`f`b
`B100`F9d9 lastModified = "2013-02-12",`f`b
`B100`F9d9 teamMembers = { "Ann", "Dan", "Fran" },`f`b
`B100`F9d9 meaningOfLife = 42)`f`b
`B100`F9d9`f`b
`B100`F9d9public class SetCustomAnnotation {`f`b
`B100`F9d9 // Class contents go here`f`b
`B100`F9d9}`f`b

`B100`F9d9// This is the example code that processes the annotation`f`b
`B100`F9d9import java.lang.annotation.Annotation;`f`b
`B100`F9d9import java.lang.reflect.AnnotatedElement;`f`b
`B100`F9d9`f`b
`B100`F9d9public class UseCustomAnnotation {`f`b
`B100`F9d9 public static void main(String [] args) {`f`b
`B100`F9d9 Class<SetCustomAnnotation> classObject = SetCustomAnnotation.class;`f`b
`B100`F9d9 readAnnotation(classObject);`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 static void readAnnotation(AnnotatedElement element) {`f`b
`B100`F9d9 try {`f`b
`B100`F9d9 System.out.println("Annotation element values: \\n");`f`b
`B100`F9d9 if (element.isAnnotationPresent(TypeHeader.class)) {`f`b
`B100`F9d9 // getAnnotation returns Annotation type`f`b
`B100`F9d9 Annotation singleAnnotation =`f`b
`B100`F9d9 element.getAnnotation(TypeHeader.class);`f`b
`B100`F9d9 TypeHeader header = (TypeHeader) singleAnnotation;`f`b
`B100`F9d9`f`b
`B100`F9d9 System.out.println("Developer: " + header.developer());`f`b
`B100`F9d9 System.out.println("Last Modified: " + header.lastModified());`f`b
`B100`F9d9`f`b
`B100`F9d9 // teamMembers returned as String []`f`b
`B100`F9d9 System.out.print("Team members: ");`f`b
`B100`F9d9 for (String member : header.teamMembers())`f`b
`B100`F9d9 System.out.print(member + ", ");`f`b
`B100`F9d9 System.out.print("\\n");`f`b
`B100`F9d9`f`b
`B100`F9d9 System.out.println("Meaning of Life: "+ header.meaningOfLife());`f`b
`B100`F9d9 }`f`b
`B100`F9d9 } catch (Exception exception) {`f`b
`B100`F9d9 exception.printStackTrace();`f`b
`B100`F9d9 }`f`b
`B100`F9d9 }`f`b
`B100`F9d9}`f`b

>>See also

• `F33f`_`[Jakarta Annotations`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Jakarta_Annotations]`_`f
• `F33f`_`[CLI Attributes`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Metadata_(CLI)]`_`f
• `F33f`_`[Java`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_(programming_language)]`_`f
• `F33f`_`[Java virtual machine`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_virtual_machine]`_`f
• `F33f`_`[Model-driven architecture`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Model-driven_architecture]`_`f
• `F33f`_`[Python decorators`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Python_syntax_and_semantics]`_`f, inspired by Java annotations, which have a similar syntax.

>>References

`:cite-note-1`!1.`! `F0af`_`[↑`#cite-ref-1]`_`f "Annotations". `F33f`_`[Sun Microsystems`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Sun_Microsystems]`_`f. Archived from the original on 2011-09-25. Retrieved 2011-09-30..
`:cite-note-2`!2.`! `F0af`_`[↑`#cite-ref-2]`_`f `:citerefsun-microsystems2005`a`F33f`_`[Sun Microsystems`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Sun_Microsystems]`_`f (2005). `*Java(TM) Language Specification`* (3rd ed.). `F33f`_`[Prentice Hall`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Prentice_Hall]`_`f. `F33f`_`[ISBN`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ISBN_(identifier)]`_`f 0-321-24678-0..
`:cite-note-3`!3.`! `F0af`_`[↑`#cite-ref-3]`_`f `:citerefdare-obasanjo2007`aDare Obasanjo (2007). "A COMPARISON OF MICROSOFT'S C# PROGRAMMING LANGUAGE TO SUN MICROSYSTEMS' JAVA PROGRAMMING LANGUAGE: Metadata Annotations". Dare Obasanjo. Archived from the original on 2012-09-19. Retrieved 2012-09-20.
`:cite-note-4`!4.`! `F0af`_`[↑`#cite-ref-4]`_`f `:citerefcoward2006`aCoward, Danny (2006-11-02). "JSR 175: A Metadata Facility for the JavaTM Programming Language". `F33f`_`[Java Community Process`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_Community_Process]`_`f. Retrieved 2008-03-05.
`:cite-note-5`!5.`! `F0af`_`[↑`#cite-ref-5]`_`f "Predefined Annotation Types". `F33f`_`[Oracle Corporation`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Oracle_Corporation]`_`f. Retrieved 2016-12-17.
`:cite-note-6`!6.`! `F0af`_`[↑`#cite-ref-6]`_`f "The Built-In Annotations : Standard Annotations". Retrieved 2016-12-17.

>>External links

• Introduction to Java 6 Annotations at Sun Developer Network Site
• An Introduction to Java Annotations by M. M. Islam Chisty
• `:citerefsrinivasan2007`aSrinivasan, Krishna (August 11, 2007). "Annotations in Java 5.0". `*JavaBeat`*. Archived from the original on May 31, 2015.
• `:citerefhunt2006`aHunt, John (24 Feb 2006). "Of Java Annotations". `*The Register`*.
• "How to create and implement custom annotations in Java?". `*So Many Word`*. February 15, 2014. Archived from the original on Feb 23, 2014.
• "Java Annotations Tutorial with examples". `*TutorialsDesk`*. October 9, 2014.
• `:citerefthakor2015`aThakor, Vicky (13 October 2015). "Understanding Annotations in Java". `*Java by examples`*.

`c`F0af`_`[↑ Back to top`#top]`_`f`a